<template>
	<view class="container">
		<u-navbar title="身份认证" :background="{ background: '#6EC9E1' }" :fixed="true" :border-bottom="false"
			title-color="#FFF" back-icon-color="#FFF">
		</u-navbar>

		<view class="card form">
			<view class="form-item">
				<span>姓名</span>
				<input type="text" v-model="userInfo.settlement_name" placeholder="请输入真实姓名"
					placeholder-class="placeholder">
			</view>
			<u-line margin='25rpx 0'></u-line>
			<view class="form-item">
				<span>电话号码</span>
				<input type="text" v-model="userInfo.settlement_mobile" placeholder="请输入预留号码"
					placeholder-class="placeholder">
			</view>
			<u-line margin='25rpx 0'></u-line>
			<view class="form-item">
				<span :style="isIdCard?'':'color:red;'">{{isIdCard?'':'*'}} 身份证号码</span>
				<input type="text" @blur="rule" v-model="userInfo.idcard" placeholder="请输入身份证号"
					placeholder-class="placeholder">
			</view>
			<u-line margin='25rpx 0'></u-line>
			<view class="form-item">
				<span :style="isBankCard?'':'color:red;'">{{isBankCard?'':'*'}} 银行卡号</span>
				<input type="text" @blur="rulex" v-model="userInfo.bank_card" placeholder="请输入银行卡号"
					placeholder-class="placeholder">
			</view>
			<u-line margin='25rpx 0'></u-line>
			<view class="form-item">
				<span>银行及支行</span>
				<input type="text" v-model="userInfo.bank_name" placeholder="银行及支行名称" placeholder-class="placeholder">
			</view>
			
			<u-line margin='25rpx 0'></u-line>
			<view class="form-item">
				<span>发票代码</span>
				<input type="text" v-model="userInfo.invoice_code" placeholder="发票代码" placeholder-class="placeholder">
			</view>
			
			
			<u-line margin='25rpx 0'></u-line>
			<view class="form-item">
				<span>发票号码</span>
				<input type="text" v-model="userInfo.invoice_number" placeholder="发票号码" placeholder-class="placeholder">
			</view>
			
		</view>

		<view class="card ">
			<p>上传身份证照片 </p>
			<view class="upload">
				<view class="left">
					<u-upload ref="uUpload" :custom-btn="true" :show-progress='false' image-mode='widthFix'
						@on-change="idcard_front_img" @on-remove="remove_idcard_front_img" :size-type="['compressed']"
						name="file" width="254" height="190" :form-data="uploadFormData" :action="uploadAction"
						:max-count="1" :file-list="avatarFileList">
						<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
							<image
								:src="userInfo.idcard_front_img?userInfo.idcard_front_img:'../../static/img/uploadImg.png'"
								mode=""></image>
						</view>
					</u-upload>
					<p>身份证正面</p>
				</view>


				<view class="right">
					<u-upload image-mode='widthFix' :custom-btn="true" :show-progress='false' ref="uUpload"
						@on-change="idcard_feverse_img" @on-remove="remove_idcard_feverse_img"
						:size-type="['compressed']" name="file" width="254" height="190" :form-data="uploadFormData"
						:action="uploadAction" :max-count="1" :file-list="avatarFileList">
						<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
							<image
								:src="userInfo.idcard_feverse_img?userInfo.idcard_feverse_img:'../../static/img/uploadImg.png'"
								mode=""></image>
						</view>
					</u-upload>
					<p>身份证反面</p>
				</view>
			</view>
		</view>

		<view class="next" @click="save()">保存</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		appleDoctor
	} from '../../api/login/login.js'
	import {
		editSettlementInfo,
		getUserInfo
	} from '@/api/index.js'
	export default {
		data() {
			return {
				userInfo: {},
				uploadAction: '',
				uploadFormData: new Object(),
				isIdCard: true,
				isBankCard: true
			}
		},
		onLoad() {
			this.uploadAction = this.ws.upload
			this.init()
		},
		methods: {
			init() {
				getUserInfo({
					'user_id': this.ws.getUserInfo().user_id
				}).then(res => {
					if (res.code) {
						this.userInfo = res.data.info
					} else {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error '
						})
					}
				})
			},
			save() {
				if (!this.userInfo.settlement_name) {
					this.$refs.uToast.show({
						title: '缺少姓名',
						type: 'error '
					})
					return
				};
				if (!this.isIdCard) {
					this.$refs.uToast.show({
						title: '身份证错误',
						type: 'error '
					})
					return
				};
				if (!this.userInfo.idcard_front_img) {
					this.$refs.uToast.show({
						title: '缺少身份证正面',
						type: 'error '
					})
					return
				};
				if (!this.userInfo.idcard_feverse_img) {
					this.$refs.uToast.show({
						title: '缺少身份证反面',
						type: 'error '
					})
					return
				};



				editSettlementInfo(this.userInfo).then(res => {
					if (res.code) {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'success'
						})
					} else {
						this.$refs.uToast.show({
							title: '提交失败' + res.msg,
							type: 'error '
						})
					}

				})

			},
			rule() {
				this.isIdCard = /^([1-9]\d{5})(\d{4})(\d{2})(\d{2})(\d{3})(\d|X)$/.test(this.userInfo.idcard)
			},
			rulex() {
				this.isBankCard = /^\d{16,19}$/.test(this.userInfo.idcard)
			},
			avatarOnSuccess: function(data, src) {
				return this.ws.imgUrl(data.data.fullurl)

			},
			idcard_front_img: function(res, index, lists) {
				res = JSON.parse(res.data);
				if (res.code == 1) {
					this.userInfo.idcard_front_img = this.avatarOnSuccess(res)
				}

			},
			remove_idcard_front_img() {
				this.userInfo.idcard_front_img = ''
			},
			idcard_feverse_img: function(res, index, lists) {
				res = JSON.parse(res.data);
				if (res.code == 1) {
					this.userInfo.idcard_feverse_img = this.avatarOnSuccess(res)
				}

			},
			remove_idcard_feverse_img() {
				this.userInfo.idcard_feverse_img = ''
			},
			certificate: function(res, index, lists) {
				res = JSON.parse(res.data);
				if (res.code == 1) {
					this.userInfo.certificate = this.avatarOnSuccess(res)
				}
			},
			remove_certificate() {
				this.userInfo.certificate = ''
			}
		}
	}
</script>

<style lang="less">
	.container {
		background: url('../../static/img/mine/header-bg.png');
		background-size: 100% 30vh;
		background-repeat: no-repeat;
		padding: 30rpx;
		background-color: #EEE;
		font-family: Microsoft JhengHei;
		font-size: 14px;

		.next {
			width: 90%;
			position: fixed;
			bottom: 30px;
			margin: 0 auto;
			border-radius: 30px;
			color: #FFF;
			text-align: center;
			line-height: 50px;
			height: 50px;
			background-color: #6EC9E1;
		}

		.form {
			width: 100%;

			.form-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;

				input {
					padding-right: 20rpx;
					text-align: right;
				}

				.placeholder {
					display: flex;
					justify-content: flex-end;
				}
			}
		}

		.card {
			margin-top: 20rpx;
			background-color: #FFF;
			border-radius: 20rpx;
			padding: 30rpx;
		}

		.upload {
			display: flex;
			justify-content: space-around;
			text-align: center;
			padding: 20rpx 0;

			image {
				height: 190rpx;
				width: 254rpx;
				margin: 10rpx;
			}

			.image {
				height: 360rpx !important;
				width: 300rpx !important;
			}
		}


	}
</style>